﻿using System.Runtime.InteropServices;

namespace OpenLS.Spreadsheet.Formats.Biff.Cryptography
{
    internal static class CryptoApi
    {
        public const int CRYPT_NEWKEYSET = 0x00000008;
        public const int NTE_BAD_KEYSET = -2146893802;
        public const int PROV_RSA_FULL = 1;
        public const int PROV_RSA_AES = 24;
        public const int CRYPT_SILENT = 0x40;
        private const int ALG_CLASS_HASH = (4 << 13);
        private const int ALG_TYPE_ANY = 0;
        public const int HP_HASHVAL = 0x0002;  
        public const int CRYPT_MACHINE_KEYSET = 0x00000020;
        private const int ALG_SID_MD4 = 2;
        public const int CALG_MD4 = (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD4);

        [DllImport(@"advapi32.dll", EntryPoint = "CryptAcquireContextA", CharSet = CharSet.Ansi, SetLastError = true)]
        internal static extern int CryptAcquireContext(ref int phProv, string pszContainer, string pszProvider, int dwProvType, int dwFlags);

        [DllImport(@"advapi32.dll")]
        internal static extern int CryptReleaseContext(int hProv, int dwFlags);

        [DllImport(@"advapi32.dll", EntryPoint = "CryptCreateHash")]
        internal static extern int CryptCreateHash(int hProv, int algid, int hKey, int dwFlags, out int phHash);

        [DllImport(@"advapi32.dll", EntryPoint = "CryptDestroyHash")]
        internal static extern int CryptDestroyHash(int hHash);

        [DllImport(@"advapi32.dll", EntryPoint = "CryptHashData")]
        internal static extern int CryptHashData(int hHash, byte[] pbData, int dwDataLen, int dwFlags);

        [DllImport(@"advapi32.dll", EntryPoint = "CryptGetHashParam")]
        internal static extern int CryptGetHashParam(int hHash, int dwParam, byte[] pbData, ref int pdwDataLen, int dwFlags);
    }
}
